<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>Insert title here</title>
</head>
<body>
<fieldset class="layui-elem-field" style='margin:20px;padding:20px'>
  <legend>信息维护</legend>
  <div class="layui-field-box">
   	<form class="layui-form layui-form-pane" lay-filter='formA'>
	  <div class="layui-form-item">
	    <label class="layui-form-label">编号</label>
	    <div class="layui-input-inline">
	      <input type="text" name="code" required  lay-verify="required" 
	      readonly autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">部门</label>
	    <div class="layui-input-inline">
	      <select name="depCode"></select>
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-input-inline">
		  <input type="button" class="layui-btn" lay-submit lay-filter="upddept" value="确定">		   
	      <input type="button" class="layui-btn layui-btn-primary" value="重置" onclick="init()">
	    </div>
	    <input type="button" class="layui-btn" value="关闭" onclick="toClose()">
	  </div>
	  <input type="hidden" name="action" value="upddept"  />
	</form>
  </div>
</fieldset>

<script type="text/javascript">
//初始化下拉框数据
initSelect();
function initSelect(){
	ajax("/department",{action:'sel'},'json',function(data){
		console.log(data)
		var html='<option value=""></option>'
		$.each(data,function(index,element){
			html+='<option value="'+this.code+'">'+this.name+'</option>'
		})
		$("select[name='depCode']").html(html);
		form.render();//渲染，动态改变页面
		init();
	})
}
// 
function init(){//回显
	  var code='<%=request.getParameter("code") %>'
	  ajax("/employee",{code:code,action:'get'},'json',function(data){
// 			console.log(data)
			form.val("formA",data);
// 			$("input[name='code']").val(data.code)
// 			$("input[name='name']").val(data.name)
// 			$("input[name='depCode']").val(data.depCode)
		})
}

	formOn("/employee",'submit(upddept)',"text",function(data){
//	console.log(data)
	 if("1"==data){
		layer.msg("修改成功",toClose)
	}else{
		layer.msg("修改失败");
	}
})
</script>
</body>
</html>